class SingleDog {
  
  constructor() {
    // this.count = 0
    // this.obj = null
  }
  show() {
    console.log('我是个单例对象')
  }
  // static getInstance() {
  //   if (this.count) {
  //     return this.obj
  //   }
  //   this.count++
  //   this.obj = new SingleDog()
  //   return this.obj
  // }
  // 下面这个是单例的实现方案
  static getInstance() {
    if (!SingleDog.instance) {
      SingleDog.instance = new SingleDog()
    }
    return SingleDog.instance
  }

  

}

// const s1 = new SingleDog()
// const s2 = new SingleDog()
     
const s1 = SingleDog.getInstance()
const s2 = SingleDog.getInstance()
console.log(s1 === s2);




